static inline __int32 InterlockedCompareExchange(volatile __int32 *dest, __int32 exch, __int32 comp)
{
	__int32 last;
	__asm__ __volatile__ ("lock; cmpxchgl %2, %0"
			      : "=m"(*dest), "=a"(last)
			      : "r"(exch), "m"(*dest), "a"(comp));	
	return(last);
}

#define SPINLOCK(lock) while(InterlockedCompareExchange((__int32*)&lock, 1, 0) != 0)
#define SPINUNLOCK(lock) lock = 0